package short_semester.questionnaire_planet.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import short_semester.questionnaire_planet.pojo.Questionnaire;
import short_semester.questionnaire_planet.pojo.SingleChoiceQuestion;

import javax.transaction.Transactional;
import java.util.List;

public interface SingleChoiceQuestionDao extends JpaRepository<SingleChoiceQuestion,Integer> {
    
    public List<SingleChoiceQuestion> findByQuestionnaire(Questionnaire questionnaire);
    
    public int countByQuestionnaire(Questionnaire questionnaire);

    @Modifying
    @Transactional
    @Query("update SingleChoiceQuestion q set q.count=q.count+1 where q.id=:id")
    void submitQuestion(Integer id);
    
}
